﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using ModuleDALCore;

namespace DAL
{
	public class USERSDAO:DALBase
	{
		public USERSDAO()
		{
			this.OpenConnect();
		}
		private DataTable dt;
		private string _SpName;

		public string SpName
		{
			get { return "SPUSERSW"; }
			set { _SpName = value; }
		}
		public List<USERS> GetListUSER()
		{
			List<USERS> USERSc = new List<USERS>();
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new USERS(), null), ConvertClassToArray.GetValues(new USERS(), 0));
				USERSc = (List<USERS>)ConvertDatatableToList.ConvertTo<USERS>(dt);
			}
			catch { return null; }// throw new InvalidExpressionException("Msg1: Can't list BN"); }
			return USERSc;
		}
		public DataTable GetListUSERs()
		{
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new USERS(), null), ConvertClassToArray.GetValues(new USERS(), 0));
				return dt;
			}
			catch { return null; }// throw new InvalidExpressionException("Msg1: Can't list BN"); }
		}
		public String CreatenewId()
		{
			try
			{
				return "USR" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new USERS(), null), ConvertClassToArray.GetValues(new USERS(), 1));

			}
			catch { return null; }// throw new InvalidExpressionException("Msg1: Can't Create new USR"); }
		}
		public bool INSERT(USERS cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

			}
			catch { return false; }// throw new InvalidExpressionException("Msg1: Can't Insert new USR"); }
		}
		public bool UPDATE(USERS cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

			}
			catch { return false; }// throw new InvalidExpressionException("Msg1: Can't Update  USR"); }
		}
		public bool DELETE(USERS cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 4)) == 1);

			}
			catch { return false; }// throw new InvalidExpressionException("Msg1: Can't Delete  USR"); }
		}
		public bool ISLOGIN(USERS urs)
		{
			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(urs, null), ConvertClassToArray.GetValues(urs, 5)) == 1);

			}
			catch { return false; }// throw new InvalidExpressionException("Msg1: Can't Delete  USR"); }
		}
		public USERS GETUSER(USERS urs)
		{
			USERS USERSc = new USERS();
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(urs, null), ConvertClassToArray.GetValues(urs, 6));
				USERSc = (USERS)ConvertDatatableToList.ConvertToObject<USERS>(dt);
			}
			catch { return null; }// throw new InvalidExpressionException("Msg1: Can't list BN"); }
			return USERSc;
		}
		public bool ISEXISTSUSERNAME(USERS urs)
		{
			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(urs, null), ConvertClassToArray.GetValues(urs, 7)) == 1);

			}
			catch { return false; }// throw new InvalidExpressionException("Msg1: Can't Delete  USR"); }
		}
		public bool ISADMIN(USERS urs)
		{
			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(urs, null), ConvertClassToArray.GetValues(urs, 8)) == 1);

			}
			catch { return false; }// throw new InvalidExpressionException("Msg1: Can't Delete  USR"); }
		}
	}
}
